<?php

use yii\db\Migration;

class m180517_061043_create_comments extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%comments}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'title' => $this->string(255)->defaultValue(0)->comment('标题'),
                'description' => $this->string(255)->defaultValue(0)->comment('评论描述 '),
                'user_id' => $this->integer(11)->defaultValue(0)->comment('管理员id'),
                'valuator_type' => $this->smallInteger(1)->defaultValue(0)->comment('评价者类型（1学生2老师3教辅总监）'),
                'valuator_id' => $this->integer(11)->defaultValue(0)->comment('评价者id'),
                'accepter_type' => $this->smallInteger(1)->defaultValue(0)->comment('被评价者类型（1学生2老师3教辅总监）'),
                'accepter_id' => $this->integer(11)->defaultValue(0)->comment('被评价者id'),
                'lesson_student_id' => $this->integer(11)->defaultValue(0)->comment('成长日志id'),
                'status' => $this->smallInteger(1)->defaultValue(0)->comment('状态（0关闭1正常）'),
                'created_at' => $this->integer(11)->defaultValue(0)->comment('添加时间'),
                'updated_at' => $this->integer(11)->defaultValue(0)->comment('修改时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%comments}}');
        }
    }
}
